package com.yutian.tomcatservlet;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class MyFirstServlet implements Servlet {

    //该函数用于初始化servelet就是把该servlet装载到内存中
    //该函数只会被调用一次
    public void init(ServletConfig config) throws ServletException {

    }

    public void init() throws ServletException {

    }

    //得到ServeletConfig对象
    public ServletConfig getServletConfig() {
        return null;
    }

    //该函数是服务函数，我们的业务逻辑代码就是写在这里
    //该函数每次都会被调用
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        System.out.println("处理service()请求...");
        PrintWriter out =response.getWriter();
        //指定文件的输出类型
        response.setContentType("text/html;charset=utf-8");
        out.println("<strong>MyFirstServlet with service!</strong><br>");
    }

    //g该函数使得到servlet配置信息
    public String getServletInfo() {
        return null;
    }

    //销毁该servlet，从内存中清除掉，仅会被调用一次
    public void destroy() {

    }
}
 
